<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
		
        <div class="container mt-1">
          <el-form inline size="small">
			<div class="flex items-center search_form">
				<div>
					用户id：
					<el-input
					v-model="searchForm.user_id"
					placeholder="请输入用户id"
					style="width: 200px; margin-right: 10px;"
					size="small"
					></el-input>
				</div>
				<div>
					类型：
					<el-select
					v-model="searchForm.type"
					placeholder="请选择"
					style="width: 200px; margin-right: 10px;"
					size="small"
					>
                     <el-option label="不限" value="-1"></el-option>
					  <el-option label="赠送" value="1"></el-option>
					  <el-option label="兑换" value="2"></el-option>
					</el-select>
				</div>
				<div>
					添加时间：
					<el-date-picker
					v-model="time"
					type="daterange"
					value-format="yyyy-MM-dd"
					range-separator="至"
					start-placeholder="开始日期"
					end-placeholder="结束日期"
					style=" margin-right: 10px;"
					size="small"
					></el-date-picker>
				</div>
				
				 <div style="margin-left: 10px;">
					<el-button type="primary" size="mini" @click="mySearch">搜索</el-button>
					<el-button size="mini" @click="reset">重置</el-button>
					<!-- <el-button type="primary" size="mini" @click="addBtn">添加</el-button> -->
				 </div>
			</div>
			
           
			
           
          </el-form>
        </div>
      </div>
      <el-table
        :data="list"
        style="width: 100%"
        size="mini"
        height="600px"
        :highlight-current-row="true"
        :header-cell-style=" {fontWeight:'bold'}"
      >
        <el-table-column
          prop="id"
          label="ID"
          min-width="50"
        />
       <el-table-column label="兑换商品名称"
	  					align="center"
                         prop="goods_name"
                         min-width="100"
                         :show-overflow-tooltip="true">
	  		<template slot-scope="scope">
				<span>{{scope.row.goods_name || '--'}}</span>
			</template>
        </el-table-column>
		<el-table-column label="用户昵称"
		                 prop="nick_name"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
		</el-table-column>
        <el-table-column label="用户ID"
		                 prop="user_id"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
		</el-table-column>
        <el-table-column label="类型"
		                 prop="uid"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
            <template slot-scope="scope">
                <el-tag v-if="scope.row.type==1" type="info" effect="dark" size="small">赠送</el-tag>
                <el-tag v-if="scope.row.type==2" type="danger" effect="dark" size="small">兑换</el-tag>
            </template>
        </el-table-column>
		<el-table-column label="添加时间"
		                 prop="add_time"
						width="200"
						 align="center">
		</el-table-column>
		<el-table-column label="积分"
		                 prop="points"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
		</el-table-column>
		
        <!-- <el-table-column label="操作" min-width="130" fixed="right">
          <template slot-scope="scope">
			<el-button type="text" @click="editRow(scope.row)">编辑</el-button>
			<el-button type="text" @click="delRow(scope.row.id)">删除</el-button>
          </template>
        </el-table-column> -->
      </el-table>
	  <div class="page">
	              <el-pagination
	                      background
	                      @size-change="pageChange"
	                      @current-change="handleCurrentChange"
	                      :current-page="page"
	                      :page-size="pageSize"
	                      layout="total, sizes, prev, pager, next, jumper"
	                      :total="page_totle">
	              </el-pagination>
	          </div>
    </el-card>
	
	<!-- 新增角色 -->
	<el-dialog
	  :title="title"
	  :visible.sync="formShow"
	  :close-on-click-modal="false"
	  width="600px">
	  <el-form ref="form" :model="form" label-width="120px">
		  <el-form-item label="状态" prop="age">
			<el-select v-model="form.status" style="width: 200px; margin-right: 10px;" size="small" placeholder="请选择状态">
				<el-option
				v-for="item in statusOptions"
				:key="item.value"
				:label="item.label"
				:value="item.value"
				></el-option>
			</el-select>
		  </el-form-item>
		  <el-form-item label="物流名称" prop="logistics_name">
			<el-input v-model="form.deliveryName" placeholder="请输入物流名称" size="small"></el-input>
		  </el-form-item>
		  <el-form-item label="物流编号" prop="logistics_no">
			<el-input v-model="form.deliveryCode" placeholder="请输入物流编号" size="small"></el-input>
		  </el-form-item>
		  
	  </el-form>
	  <span slot="footer" class="dialog-footer">
	    <el-button size="mini" @click="formShow = false">取 消</el-button>
	    <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
	  </span>
	</el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        title:'新增',
		form:{
			id:null,
			status:0, //状态
			deliveryName:'', //物流名称
			deliveryCode:'', //物流编号
		},
		list:[],
		page:1,
		pageSize:10,
		searchForm:{
			name:"",
            aid:"", //奖品id
		},
		time:[],
        options:[], //奖品列表
		statusOptions:[
			{
				value:'0',
				label:'未领取'
			},
			{
				value:'1',
				label:'已领取未发货'
			},
			{
				value:'2',
				label:'已领取已发货'
			},
			{
				value:'3',
				label:'已完成'
			}
		]
      }
    },
    mounted() {
		this.lodeList()
        this.getPrizeList()
    },
    methods: {
        //获取奖品列表
        getPrizeList(){
				 
		  this.$api.post('/admin/getPrizeList',{searchForm:{}}).then(res=>{
			  let data = res.data
             this.options = data.result
		  })
		},
		
		addBtn(){
			this.form = {
				id:null,
                name:"",
                probability:"", //概率
                desc:'', //备注
			}
			this.title = '新增'
			this.formShow = true
		},

		reset(){
			this.searchForm = {
				name:"",
                aid:"", //奖品id
			}
			this.time = []
			this.mySearch()
		},
		
		editRow(row,type){
			console.log(row)
			this.type = type
			this.title = '编辑'
			for(let i in this.form){
				this.form[i] = row[i]
			}
			this.formShow = true
		
		},
		
		confirm(){
		
		    this.$api.post('/admin/editWinRecord',this.form).then(res=>{
		    	  if(res.code==200){
					  this.formShow = false
		    	  	  this.lodeList()
		    	  }
		    })
		},
		delRow(id){
			this.$confirm('确定删除', '提示', {
					  confirmButtonText: '确定',
					  cancelButtonText: '取消',
					  type: 'warning'
					}).then(() => {
						let params = {
							dd:{id}
						}
					  this.$api.post('/admin/delAwardHistory',params).then(res=>{
					  	  if(res.code==200){
					  	  	this.lodeList()
					  	  }
					  })
			  })
	   },
      lodeList(){
         if(this.time.length>0){
			this.searchForm.start_time = this.time[0]
			this.searchForm.end_time = this.time[1]
		  }
		  let params = {
		          	page:this.page,
		          	pageSize:this.pageSize,
					searchForm:this.searchForm
		    }
		 
		  this.$api.post('/admin/getPointExchangeDetail',params).then(res=>{
			  let data = res.data
			  this.page_totle = data.count
			  this.list = data.result
		  })
	  }
      
    }
  }
</script>
